package com.smwish;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.users.User;

import java.util.Date;
import java.util.List;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable
public class Wish {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

    @Persistent
    private User author;

    @Persistent
    private String content;

    @Persistent
    private Date date;

    @Persistent
    private int	votes;	//The number of votes
    
    @Persistent
    private List<User> voteUserList; //The vote (non-anonymous) user list 
    
    public Wish(User author, String content, Date date) {
        this.author = author;
        this.content = content;
        this.date = date;
    }

    public Key getKey() {
        return key;
    }

    public User getAuthor() {
        return author;
    }

    public String getContent() {
        return content;
    }

    public Date getDate() {
        return date;
    }

    /**
     * Return the publish time in string
     * if it is published within an hour, return "xx分钟前";
     * if it is published within a day, return "xx小时前"; 
     * if it is published within a month, return "xx天前";
     * Otherwise, return "yyyy-MM-dd";
     */
    public String getWishDateString(){
    	return WishUtil.wishDateFormat(date);
    }
    
    public void setAuthor(User author) {
        this.author = author;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public void setDate(Date date) {
        this.date = date;
    }

	public void setVotes(int votes) {
		this.votes = votes;
	}

	public void incrVotes(User voter){
		this.votes ++;
		if( voter != null)
			voteUserList.add(voter);
	}
	public int getVotes() {
		return votes;
	}

	public void setVoteUserList(List<User> voteUserList) {
		this.voteUserList = voteUserList;
	}

	public List<User> getVoteUserList() {
		return voteUserList;
	}
}
